package library.http;

import java.lang.reflect.Proxy;

public class Http {

    public static HttpTask obtain(Object anchor) {
        return new HttpTask().tag(anchor);
    }

    public static <T> T load(Class<? extends T> server) {
        return load(server, null);
    }

    public static <T> T load(Class<? extends T> server, HttpAdapter adapter) {
        HttpUtils.checkInterface(server);
        Object ret = Proxy.newProxyInstance(
                server.getClassLoader(),
                new Class<?>[]{server},
                new InvokeHandler(server, adapter));
        return (T) ret;
    }


    public static void cancel(Object token) {
        HttpManager.cancel(token);
    }

    public static void cancelAll() {
        HttpManager.cancelAll();
    }
}
